var User={
	//根据手机号查询用户
	//一定要加双引号
	
	queryUserName(params){
		if(params.userPhone){		return "select * from user where nickName = '"+params.userPhone+"' or phone = '"+params.userPhone+"' ";
}else{
	//第三方登录
	return "select * from user where provider = '"+params.provider+"' or openid = '"+params.openid+"' ";
}

		// return `select * from user where phone = ${params.userPhone} or nickName = ${params.userPhone} `
	},
	//验证用户名和密码
	queryUserPwd(params){
			console.log(params,"查询昵称");
		return `select * from user where nickName = "${params.userPhone}"  or phone = "${params.userPhone}" and userPwd ="${params.userPwd}"`
	},
	//增加一条用户数据
	insertData(params){
		console.log(params,"增加");
		let userPhone =params.userPhone || params.openid.slice(0,11);
	const jwt = require('jsonwebtoken');
		let payload={phone:userPhone}//手机号 必须是对象形式
		let secert ='haowu' //口令
		let token =jwt.sign(payload,secert)
		let nickName = params.nickName || "默认昵称";
		let avatarUrl = params.avatarUrl || "https://i0.hdslb.com/bfs/face/93795d63c3cf6e3d9265cd37414aa96f378a5eed.jpg@150w_150h.jpg";
		return "insert into user (userPwd,phone,imgUrl,nickName,token,provider,openid) value ('123456','"+userPhone+"','"+avatarUrl+"','"+nickName+"','"+token+"','"+params.provider+"','"+params.openid+"')"
	}
}
exports = module.exports=User